// apiUtils.js (处理API请求)
import { selectTable } from './tableUtils';

// 去请求数据获取表格默认选中事件
export const fetchData = async (
  api,
  params,
  dataRef,
  combinedValues = {},
  ruleType,
  isMajor,
  isLastpage,
) => {
  try {
    const { data } = await api(params);
    const { selectMarjorList, selectCollegeList } = combinedValues.value;
    if (!data.data.length) isLastpage.value = true;
    dataRef.value = [...dataRef.value, ...data.data];
    if (ruleType.value != 3) {
      selectTable(
        dataRef.value,
        isMajor ? selectMarjorList : selectCollegeList,
      );
    }
  } catch (error) {
    console.error('Error fetching data:', error);
  }
  return dataRef.value;
};
